<?php

/*
 * CopyRight  : (C)2012-2099 HaoTeam Inc.
 * Document   : Log.php
 * Created on : 2021-1-31 10:34:27
 * Author     : Tiger <1192851302@qq.com>
 * Description: This is NOT a freeware, use is subject to license terms.
 *              这即使是一个免费软件,使用时也请遵守许可证条款,得到当时人书面许可.
 *              未经书面许可,不得翻版,翻版必究;版权归属 HaoTeam Inc;
 */

namespace app\admin\controller;

use haoteam\service\UtilService;
use app\admin\model\AdminActionLog;

/**
 * 系统日志管理
 * Class Log
 * Tiger <1192851302@qq.com> 2021-1-31 10:34:27
 */
class Log {

    /**
     * 系统日志管理
     * @auth true
     * @menu true
     * @author Tiger <1192851302@qq.com>
     * @return type
     */
    public function index() {
        $post = UtilService::postMore([
                    'username',
                    'node',
                    'action',
                    'content',
                    'geoip',
                    'create_time'
        ]);
        return app('json')->successful(AdminActionLog::getList($post));
    }

    /**
     * 日志行为列表
     * @login true
     * @author Tiger <1192851302@qq.com>
     * @return type
     */
    public function get_action() {
        return app('json')->successful(AdminActionLog::distinct(true)->column('action'));
    }

    /**
     * 系统日志删除
     * @auth true
     * @author Tiger <1192851302@qq.com>
     * @return type
     */
    public function delete() {
        $post = UtilService::postMore([
                    ['ids', []]
        ]);
        if (empty($post['ids'])) {
            return app('json')->fail('参数错误ID');
        }
        try {
            AdminActionLog::whereIn('id', $post['ids'])->delete();
        } catch (\Exception $exc) {
            return app('json')->fail($exc->getMessage());
        }
        return app('json')->successful('删除成功');
    }

    /**
     * 系统日志清理
     * @auth true
     * @author Tiger <1192851302@qq.com>
     * @return type
     */
    public function clear() {
        try {
            AdminActionLog::where("1=1")->delete();
        } catch (\Exception $exc) {
            return app('json')->fail($exc->getMessage());
        }
        return app('json')->successful('清理成功');
    }

}
